package com.my.xposedbasedemo;

import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.Proxy.Type;
import java.net.URL;

import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;

public class Arrow implements IXposedHookLoadPackage {

    @Override
    public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {
        if (lpparam.packageName.equals("com.vmall.client")) {
            XposedBridge.log("绕过代理检测");
//			XposedHelpers.findAndHookMethod(System.class,"getProperty",
//		    		String.class, new XC_MethodHook() {    	
//		    	@Override
//		        protected void afterHookedMethod(MethodHookParam param) 
//		        		throws Throwable {
//		    		super.afterHookedMethod(param);
//		    		String str=(String) param.args[0];
//		    		if (str.equals("https.proxyHost") || str.equals("http.proxyHost") || 
//		    				str.equals("http.proxyPort") || str.equals("https.proxyPort")) {
//		    			param.setResult(null);
//		            }
//		        }
//		     });

            XposedBridge.log("强制代理");
            XposedHelpers.findAndHookMethod(URL.class, "openConnection",
                    new XC_MethodHook() {
                        @Override
                        protected void beforeHookedMethod(MethodHookParam param)
                                throws Throwable {
                            super.beforeHookedMethod(param);
                            param.args[0] = new Proxy(Type.HTTP, new InetSocketAddress("192.168.1.101", 8888));
                        }
                    });
        }
    }
}
